﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SiGeSIB.GUI.Common;

namespace SiGeSIB
{
    public partial class UEditDefaultToolStrip : UserControl
    {
        public event EventHandler ExitClicked;
        public event EventHandler EditClicked;
        public event EventHandler SaveClicked;
        public event EventHandler CancelClicked;

        public UEditDefaultToolStrip()
        {
            InitializeComponent();

			_FieldsToLock = new List<object>() { tsbSave, tsbCancel };
        }

		#region Attributes
		private List<object> _FieldsToLock;
		private EFormState _FormState;
		#endregion

		public void RefreshUIState(bool isEnabled, bool hasEditPermission)
		{
			bool isEdit = FormState == EFormState.Edit;
			tsbEdit.Enabled = isEnabled && !isEdit && hasEditPermission;
			tsbSave.Enabled = isEnabled && isEdit && hasEditPermission;
			tsbCancel.Enabled = isEnabled && isEdit;
			tsbExit.Enabled = isEnabled;
		}
		public EFormState FormState
		{
			get { return _FormState; }
			set
			{
				_FormState = value;
				tsbEdit.Enabled = _FormState != EFormState.Edit;
			}
		}
		public List<object> FieldsToLock { get { return _FieldsToLock; } }
        private void tsbExit_Click(object sender, EventArgs e)
        {
            if (ExitClicked != null)
                ExitClicked(sender, e);
        }
        private void tsbEdit_Click(object sender, EventArgs e)
        {
            if (EditClicked != null)
                EditClicked(sender, e);
        }
        private void tsbSave_Click(object sender, EventArgs e)
        {
            if (SaveClicked != null)
                SaveClicked(sender, e);
        }
        private void tsbCancel_Click(object sender, EventArgs e)
        {
            if (CancelClicked != null)
                CancelClicked(sender, e);
        }
    }
}
